home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qbnws204.zip / WINDOWS.ZIP / DISPLAY7.ASM < prev    next >
Assembly Source File  |  1991-07-15  |  32KB  |  608 lines

  1. ; DISPLAY.ASM ─ contains a collection of video-related procedures and
  2. ;               functions for use with Microsoft high-level languages.
  3. ;
  4. ;   Author:     Christy Gemmell
  5. ;   For:        Assembly-Language Toolbox for QuickBASIC
  6. ;   Version:    5.0
  7. ;   Date:       9/6/1991
  8. ;
  9. ;   Compatible with Microsoft Extended QuickBASIC and BASIC 7 PDS
  10. ;   Assembled using Microsoft Macro Assembler, MASM version 5.1
  11. ;
  12. ;┌────────────────────────────────────────────────────────────────────────┐
  13. ;│      Global symbols and procedures.                                    │
  14. ;└────────────────────────────────────────────────────────────────────────┘
  15. ;
  16.                 .model  medium
  17.  
  18.                 public  ScreenAddress
  19.                 public  ScreenCopy
  20.                 public  ScreenRead
  21.                 public  ScreenWrite
  22.                 public  VideoType
  23.                 public  WriteByte
  24.                 public  Attribute
  25.                 public  Delay
  26.                 public  Explode
  27.                 public  FastPrint
  28.  
  29.                 extrn   StringAddress: proc
  30.  
  31.                 .code
  32.  
  33. ;┌────────────────────────────────────────────────────────────────────────┐
  34. ;│      Data Division.                                                    │
  35. ;└────────────────────────────────────────────────────────────────────────┘
  36. ;
  37. ;   Video parameters - default to monochrome screen display
  38. ;
  39. SnowFlag        db      0                       ; Snow prevention flag
  40. VideoRam        dw      0B000h                  ; Current video segment
  41. VideoPort       dw      03BAh                   ; Current video status port
  42. Param1          label   word
  43. Mode            db      7                       ; Current screen mode  
  44. Columns         db      80                      ; Current screen width
  45. Param2          label   word
  46. Rows            db      25                      ; Current screen length
  47. ActivePage      db      0                       ; Current video page
  48. TopLeft         label   word                    ; Upper left co-ordinates
  49. H1              db      ?                       ; Horizontal length
  50. V1              db      ?                       ; Vertical height
  51. BotRight        label   word                    ; Lower right co-ordinates
  52. H2              db      ?                       ; Horizontal length
  53. V2              db      ?                       ; Vertical height
  54.  
  55. Factor          label   word
  56.                 dw      0
  57.                 dw      0
  58. Counter         label   word
  59.                 dw      ?
  60.                 dw      ?
  61. Seed            label   word
  62.                 dw      7397
  63.                 dw      29447
  64.                 dw      802
  65. Multiple        label   word
  66.                 dw      179
  67.                 dw      183
  68.                 dw      182
  69. Modulus         label   word
  70.                 dw      32771
  71.                 dw      32779
  72.                 dw      32783
  73.  
  74. ;┌────────────────────────────────────────────────────────────────────────┐
  75. ;│      Calculate address from a pair of row/column co-ordinates.         │
  76. ;└────────────────────────────────────────────────────────────────────────┘
  77. ;
  78. ;   Given the row/column column co-ordinate of a character on the screen,
  79. ;   this function returns the segment:offset address of that character in
  80. ;   video memory. The address is correctly adjusted to the start of the
  81. ;   the currently active display page, but no check is made to ensure that
  82. ;   the co-ordinates supplied are within the actual screen bounds.
  83. ;
  84. ;   Input:      AL      = Row co-ordinate of character (base zero).
  85. ;               AH      = Column co-ordinate of character (base zero).
  86. ;
  87. ;   Output:     ES:DI==>  Address in video display buffer of the
  88. ;                         character cell specified.
  89. ;               DX      = CRT status register port address.
  90. ;
  91. ;   It is assumed that a previous call has been made to the VideoType
  92. ;   function, above, to determine the screen width, the port address of
  93. ;   the CRT status register and the correct video display segment.
  94. ;
  95. ScreenAddress   proc    far
  96.                 push    ax                      ; Save working registers
  97.                 push    bx
  98.                 mov     bh,ah                   ; Column to BH
  99.                 mov     bl,cs:Columns           ; Get current screen width
  100.                 shl     bl,1                    ; Add in attribute bytes
  101.                 mul     bl                      ; Multiply by row number
  102.                 xor     bl,bl                   ; Calculate
  103.                 xchg    bh,bl                   ;    column offset
  104.                 shl     bl,1                    ;      in BX
  105.                 add     ax,bx                   ; Add it to the row offset
  106.                 mov     di,ax                   ;    and copy to DI  
  107.                 xor     ax,ax                   ; Index to ROM-BIOS
  108.                 mov     es,ax                   ;    data in low memory
  109.                 mov     ax,es:[44Eh]            ; Get offset of current page
  110.                 add     di,ax                   ; Adjust target pointer
  111.                 mov     es,cs:VideoRam          ; Return segment of video RAM
  112.                 mov     dx,cs:VideoPort         ; Return CRT status port    
  113.                 pop     bx                      ; Clean up the stack
  114.                 pop     ax
  115.                 ret                             ;    and return to caller
  116. ScreenAddress   endp
  117.  
  118. ;┌────────────────────────────────────────────────────────────────────────┐
  119. ;│      Copy a character and attribute from the video display.            │
  120. ;└────────────────────────────────────────────────────────────────────────┘
  121. ;
  122. ;   If the 'snow prevention' flag is set, this routine waits until the
  123. ;   beginning of the next CRT horizontal retrace period before reading
  124. ;   data from the display. This is necessary only on machines fitted with
  125. ;   a Colour Graphics Adaptor (CGA) which may suffer from glitches or
  126. ;   screen snow if data is copied from the screen while the video buffer
  127. ;   is being refreshed.
  128. ;
  129. ;   Input:      DS:SI==>    Address of the screen location from which
  130. ;                           the data is to be copied. 
  131. ;               ES:DI==>    Address of the buffer into which the data
  132. ;                           is to be copied.
  133. ;               DX =        Port address of CRT status register.
  134. ;
  135. ;   Output:     SI and DI   Updated to point to next buffer locations.
  136. ;               AX          destroyed.
  137. ;
  138. ScreenCopy      proc    far  
  139.                 cmp     cs:SnowFlag,0           ; Snow prevention needed?
  140.                 cli                             ; Don't interrupt!
  141.                 jz      Copy_03                 ; No, don't bother
  142. Copy_01:
  143.                 in      al,dx                   ; Read video port
  144.                 test    al,1                    ; Test bit zero
  145.                 jnz     Copy_01                 ; Wait until it's reset
  146. Copy_02:
  147.                 in      al,dx                   ; Read port again
  148.                 test    al,1                    ; Test bit zero
  149.                 jz      Copy_02                 ; Wait until it's set
  150. Copy_03:
  151.                 movsw                           ; Transfer one word
  152.                 sti                             ; Restore interrupts
  153.                 ret
  154. ScreenCopy      endp
  155.  
  156. ;┌────────────────────────────────────────────────────────────────────────┐
  157. ;│      Read a character and attribute from the display.                  │
  158. ;└────────────────────────────────────────────────────────────────────────┘
  159. ;
  160. ;   This procedure is similar to ScreenCopy, above, except that the word
  161. ;   is simply loaded into AX instead of being copied into a buffer.
  162. ;
  163. ;   Input:      DS:SI==>    address, in the video display buffer, from
  164. ;                           where the data is to be read
  165. ;               DX =        port address of the CRT status register.
  166. ;
  167. ;   Output:     AL =        character at the specified address
  168. ;               AH =        display attribute given to character
  169. ;               DI          updated to point to the next word address
  170. ;